#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

#define NUM 1024
char input[NUM];
char* my_argv[NUM];

char* getCurrentPath()
{
    char* pwd = getenv("PWD");
    pwd += strlen(pwd);
    while (*pwd != '/')
    {
        pwd--;
    }
    return pwd + 1;
}

int main()
{
    while (1)
    {
        printf("[%s@%s %s]￥ ", getenv("USER"), getenv("HOSTNAME"),getCurrentPath());
        fflush(stdin);
        fgets(input, 1024, stdin);
        input[strlen(input) - 1] = 0;
        my_argv[0] = strtok(input, " ");
        int i = 1;
        while ((my_argv[i++] = strtok(NULL, " ")))
            ;
        pid_t id = fork();
        if (id == 0)
        {
            execvp(my_argv[0], my_argv);
            exit(1);
        }
        waitpid(id, NULL, 0);
    }
    return 0;
}
